package com.mshop.fw.exception;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 
 * 
 * Title:
 * 
 * Description:
 * 
 * Copyright: Copyright (c) 2008
 * 
 * @author haoxz11
 * @created Mar 7, 2008 11:53:52 AM
 * @version $Id: BaseException.java,v 1.1 2008/03/26 06:24:08 airsou Exp $
 */
@SuppressWarnings("serial")
public class BaseException extends Exception {

	@SuppressWarnings("unused")
	private Log log = LogFactory.getLog(getClass());

	private Throwable rootCause;

	/**
	 *  
	 */
	public BaseException() {
		super();
	}

	/**
	 * @param s
	 */
	public BaseException(String s) {
		this(s, null);
		rootCause = this;
	}

	/**
	 * Creates a new BaseException object.
	 * 
	 * @param s
	 * 
	 * @param e
	 *  
	 */
	public BaseException(String s, Throwable e) {
		super(s);

		if (e instanceof BaseException) {

			rootCause = ((BaseException) e).rootCause;
		} else {

			rootCause = e;
		}

//		log.info(s, e);
	}

	/**
	 * Creates a new BaseException object.
	 * 
	 * @param e
	 */
	public BaseException(Throwable e) {
		this("", e);
	}

	/**
	 * @return
	 */
	public Throwable getRootCause() {

		return rootCause;
	}
	
	public String getErrorString(){
		StringWriter out = new StringWriter();
		printStackTrace(new PrintWriter(out));
		return out.toString();
	}
}